package com.chang.bootplus.controller;


import com.chang.bootplus.base.annotation.PublicVisit;
import com.chang.bootplus.base.utils.ApiResponse;
import com.chang.bootplus.po.*;
import com.chang.bootplus.service.MatrixShopcartService;
import com.chang.bootplus.vo.OrderVO;
import com.chang.bootplus.vo.ShopCartVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ning
 * @since 2022-01-25
 */
@RestController
@RequestMapping("/matrix-shopcart")
@Api(tags = {"购物车信息"})
@CrossOrigin(origins = "*")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class MatrixShopcartController {

    final MatrixShopcartService matrixShopcartService;

    // 查找购物车信息
    @PostMapping("list")
    @ApiOperation(httpMethod = "POST", value = "查询所有/某一用户 的购物车，或根据购物车id进行查找")
    public ApiResponse<ShopCartVO> listShopCart(@RequestBody ShopCartSelPO po){
        return matrixShopcartService.listShopCart(po);
    }

    // 添加购物车信息
    @PostMapping("add")
    @ApiOperation(httpMethod = "POST", value = "添加购物车信息,用户点击放进购物车内")
    public ApiResponse<Void> addShopCart(@RequestBody ShopCartPO po){
        return matrixShopcartService.addShopCart(po);
    }

    // 修改购物车信息 （包含修改商品状态 （如缺货等））
    @PostMapping("update")
    @ApiOperation(httpMethod = "POST", value = "修改购物车信息")
    public ApiResponse<Void> updateShopCart(@RequestBody ShopCartListPO po){
        return matrixShopcartService.updateShopCart(po);
    }

    // 删除购物车的商品信息
    @PostMapping("delete")
    @ApiOperation(httpMethod = "POST", value = "删除购物车里的一个物品信息/或为删除一个用户的所有购物车记录")
    public ApiResponse<Void> deleteShopCart(@RequestBody ShopCartIdPO po){
        return matrixShopcartService.deleteShopCart(po);
    }

    // 结算购物车  (根据传入的购物车id，全选则传入全部的id)   结算了则将其移除购物车
    @PostMapping("payShopCart")
    @ApiOperation(httpMethod = "POST", value = "结算购物车(一项或多项)")
    public ApiResponse<Void> payShopCart(@RequestBody ShopCartPayPO po){
        return matrixShopcartService.payShopCart(po);
    }

}

